import requests
import time
from logs.user_log import UserLog

log = UserLog().get_log()



def try_run(actual_do):
    def run(*args, **kwargs):
        try:
            # log.debug('执行发送请求')
            return actual_do(*args, **kwargs)
        except requests.exceptions.ConnectionError as err:
            log.error('发送请求失败！函数为--->%s()' % actual_do.__name__)
            raise Exception('ConnectionError: 发送请求失败！函数为--->%s()'.format(actual_do.__name__))
    return run


def try_default(actual_do):
    def aaa(*args, **kwargs):
        # print('try_default')
        try:
            return actual_do(*args, **kwargs)
        except:
            # print ('出现异常！函数为：%s()' % actual_do.__name__)
            log.error('出现异常！函数为-->%s()' % (actual_do.__name__))
    return aaa


def get_time(function):
    def time__(*args, **kwargs):
        function(*args, **kwargs)
        time01 = time.strftime("%Y-%m-%d %H:%M:%S")
        time.sleep(2)
        print('get_time',time01)
    return time__


def test_01(func_obj):
    def run(*args, **kwargs):
        func_obj(*args, **kwargs)
        print(args[0], '\n', func_obj(*args, **kwargs))
    return run


# class Log(object):
#     def log_id(self, func):
#         def case_id(*args, **kwargs):
#             func(*args, **kwargs)
#             param_01 = args[0]
#             print(param_01)
#             log.debug('当前用例id为：%s' % param_01)
#         return case_id
@test_01
def simple_01(x):
    return x+x


if __name__ == '__main__':
    pass
    simple_01('3')


# def out(func):
#     def inner(*args):
#         param_01 = args[0]
#         print(param_01)
#         func(*args)
#     return inner
#
# @out
# def myfunc(*args):
#     # time.sleep(1)
#     # print("args is{}".format(args))
#     pass
#
# myfunc("case_01",1)
